#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int arr[8];
    int* parr = arr;

    cout << "sizeof(arr) = " << sizeof(arr) << endl;

    char sz[] = "helloworld";
    char* psz = sz;
    cout << "sizeof(\"helloworld\") = " << sizeof("helloworld") << endl;
    cout << "sizeof(sz) = " << sizeof(sz) << endl;

    char p = 'A';
    cout << "sizeof(p) = " << sizeof(p) << endl;
    cout << "sizeof(&p) = " << sizeof(&p) << endl;


    char str1[] = "hello world";
    char str2[32] = {0};

    // 1. 循环
    char *sp = str1;
    int pos = 0;
    while(*sp != '\0') {
        str2[pos] = *sp;
        ++pos;
        ++sp;
    }
    printf("%s\n", str2);
    memset(str2, 0, 32);

    // 2. strcpy
    strcpy(str2, str1);
    printf("%s\n", str2);

    // 3. strncpy
    memset(str2, 0, 32);
    strncpy(str2, str1, 32);
    printf("%s\n", str2);

    // 4. memcpy
    memset(str2, 0, 32);
    memcpy(str2, str1, strlen(str1));
    printf("%s\n", str2);

    // 5. sprintf
    memset(str2, 0, 32);
    sprintf(str2, "%s", str1);
    printf("%s\n", str2);

    int arr1[] = {1, 2, 3, 4, 5, 6};
    int arr2[6] = {0};

    // 1. 循环
    for(int i = 0; i < 6; i++)
        arr2[i] = arr1[i];
    for(int i = 0; i < 6; i++)
        cout << arr2[i] << " ";
    cout << endl;

    // 2. memcpy
    memset(arr2, 0, sizeof(arr1));
    memcpy(arr2, arr1, sizeof(arr1));
    for(int i = 0; i < 6; i++)
        cout << arr2[i] << " ";
    cout << endl;

    return 0;
}